<!DOCTYPE html>
<html>
<head>
<title>购物车</title>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="css/shoppingcar.css" />
</head>
<body>
<div class="wrapper">
  <iframe src="./common/head.html" frameborder="0" width="1260px" height="80px" scrolling="no" name="frame3" ></iframe>
	<div id="container">
		<span class="shopping_text">已选商品</span>
		<div class="shopping_bar">
			<input type="checkbox" id="select_all_top" class="select_all" name="select_all_top">
			<span class="shopping_choice">全选</span>
			<span class="shopping_name">商品</span>
			<span class="shopping_price">单价(元)</span>
			<span class="shopping_number">数量</span>
			<span class="shopping_sum">小计</span>
			<span class="shopping_operation">操作</span>
		</div>
		<div class="shopping_list">
			<div class="shopping_show" style="border-top:2px solid #AAAAAA;">
				<div class="top_part">
					<span class="shopping_style">换购</span>
					<span class="shopping_description">活动商品购满19.90元，即可加价换购商品1件></span>
					<span class="shopping_trade">查看换购品</span>
					<span class="shopping_get">去凑单></span>
				</div>
				<div class="bottom_part">
					<input type="checkbox" id="shopping_select_first" class="shopping_select" name="shopping_select_first">		
					<div class="shopping_pic pic_one enable_edit" title="飘柔" alt="飘柔">
						<img src=""></div>
					<div class="enable_edit"><span class="shopping_desc">飘柔家庭护理山茶长效柔顺去屑洗发露400ML</span></div>
					<span class="shopping_color">颜色：山茶长效柔顺去</span> <i class="shopping_gift"></i>
					<span class="shopping_free">购买礼品包装</span>
					<div class="enable_edit">
						<span class="shopping_pay single_price" id="fuckyou">20.90</span>
					</div>
					<span class="shopping_payFor">促销优惠</span>
					<div class="number_operation">
						<div class="enable_edit">
							<a class="left_desc">-</a>
							<input type="text" class="number_show" value="" id="number_show" />						
							<a class="right_incre">+</a>
						</div>
					</div>
					<div class="enable_edit">
						<span class="price_sum" ></span>
					</div>
					<a class="first" href="">删除</a>
					<a class="second" href="">移到我的关注</a>
				</div>
			</div>
			<div class="shopping_show" style="border-top:2px solid #AAAAAA;">
				<div class="top_part">
					<span class="shopping_style">换购</span>
					<span class="shopping_description">活动商品购满19.90元，即可加价换购商品1件></span>
					<span class="shopping_trade">查看换购品</span>
					<span class="shopping_get">去凑单></span>
				</div>
				<div class="bottom_part">
					<input type="checkbox"  class="shopping_select" name="shopping_select_first">		
					<div class="shopping_pic pic_one enable_edit" title="飘柔" alt="飘柔">
						<img src=""></div>
					<div class="enable_edit"><span class="shopping_desc">飘柔家庭护理山茶长效柔顺去屑洗发露400ML</span></div>
					<span class="shopping_color">颜色：山茶长效柔顺去</span> <i class="shopping_gift"></i>
					<span class="shopping_free">购买礼品包装</span>
					<div class="enable_edit">
						<span class="shopping_pay single_price" >20.90</span>
					</div>
					<span class="shopping_payFor">促销优惠</span>
					<div class="number_operation">
						<div class="enable_edit">
							<a class="left_desc">-</a>
							<input type="text" class="number_show" value="" />						
							<a class="right_incre">+</a>
						</div>
					</div>
					<div class="enable_edit">
						<span class="price_sum" ></span>
					</div>
					<a class="first" href="">删除</a>
					<a class="second" href="">移到我的关注</a>
				</div>
			</div>

		</div>



		<div id="getAll">
			<input type="checkbox" id="select_all_bottom" class="select_all" name="select_all_bottom">
			<span class="shopping_choice" style="top:30px;">全选</span>
			<a href="" class="delete_all">删除选中的商品</a>
			<a href="" class="remove_focus">移到我的关注</a>
			<div class="car_sum">
				<span class="car_num_before">已选择</span>
				<input type="text" id="car_select" name="car_select" value="1"/>
				<span class="car_num_after">件商品</span>
				<span class="car_pay_all">总价：</span>
				<input type="text" id="car_pay" name="car_pay" value="75"/>
			</div>
			<div class="pay">
				<a href="" class="pay_all">提交订单</a>
			</div>
		</div></div>
		 <iframe src="./common/foot.html" frameborder="0" width="1260px" height="340px" scrolling="no" name="frame2" ></iframe>
	
	</div>
	<script type="text/javascript" charset="utf-8" src="./js/jquery-1.11.3.min.js"></script>
	<script type="text/javascript">
	  	$(function(){ 
	  		function getQueryStringArgs(){ 		
				var qs = (location.search.length>0?location.search.substring(1):"")
				var args = {};  
				var items = qs.split("&");  
				var item = null,    name=null,    value=null;  
				for(var i=0;i<items.length;i++){item=items[i].split("=");  
					name=decodeURIComponent(item[0]);  
					value=decodeURIComponent(item[1]);  
					args[name]=value;
				}
				return args;	
			}	
			var args=getQueryStringArgs();
			//所有商品总价,数量
	        var total_price = 0;
	        var total_amount = 0; 
			$(".enable_edit").find(".number_show").attr("value",args['purchase_number'])
			var jsonData = {
        		"goods_img_src": args['goods_img_src'],
        		"purchase_number": args['purchase_number']
     		}
	      $.ajax({
	        type: "post",
	        url: "./handler/shoppingcar.php",
	        dataType: "json",
	        data: jsonData,
	        success: function(msg) {
	        	// //所有商品总价,数量
	        	// var total_price = 0;
	        	// var total_amount = 0; 

	        	for(var i = 0 ; i<msg.objectArray.length;i++){
	        		var goods_img_src = msg.img_folder + msg.objectArray[i].img1;
	        		$(".shopping_list").children().eq(i).find(".enable_edit img").eq(i).attr("src",goods_img_src);
	        		$(".shopping_list").children().eq(i).find(".enable_edit .single_price").eq(i).text(msg.objectArray[i].Price);
	        		$(".shopping_list").children().eq(i).find(".enable_edit .shopping_desc").eq(i).text(msg.objectArray[i].Course_Name);
	        		// var purchase_number = $("#number_show").val();
	        		// var price_sum = purchase_number * msg.objectArray[i].Price ;
	        		//单个商品总价
	        		// alert(msg.objectArray[0].Amount);
	        		var price_sum = Number(msg.objectArray[i].Amount)  * Number(msg.objectArray[i].Price);
	        		total_price = total_price + price_sum;
	        		total_amount = total_amount +  Number(msg.objectArray[i].Amount) ;
	        		$(".shopping_list").children().eq(i).find(".enable_edit .price_sum").text(price_sum);
	        	}
	        		$("#car_pay").attr("value",total_price);
	        		$("#car_select").attr("value",total_amount);
	        }
	      });
			$(".enable_edit .left_desc").click(function(){
				// alert($(".number_operation .number_show ").attr("value"))

				var newValue = Number($(this).siblings('input').attr("value")) - 1;
				$(this).siblings('input').attr('value',newValue);
				var purchase_number = $("#number_show").val();
				var single_price = $(".enable_edit .single_price").text();
	        	var price_sum =Number(purchase_number)  * Number(single_price)  ;
	        	$(this).parent().parent().next().find('.price_sum').text(price_sum);
	        	total_amount = total_amount - 1;
	        	total_price = total_price - Number(single_price) ;
	        	$("#car_pay").attr("value",total_price);
	        	$("#car_select").attr("value",total_amount);
			})
			$(".enable_edit .right_incre").click(function(){
				var newValue = Number($(this).siblings('input').attr("value")) + 1;
				$(this).siblings('input').attr('value',newValue);
				var purchase_number = $("#number_show").val();
				var single_price = $(".enable_edit .single_price").text();
	        	var price_sum =Number(purchase_number)  * Number(single_price)  ;
	        	$(this).parent().parent().next().find('.price_sum').text(price_sum);
	        	total_amount = total_amount + 1;
	        	total_price = total_price + Number(single_price) ;
	        	$("#car_pay").attr("value",total_price);
	        	$("#car_select").attr("value",total_amount);

			})
			$(".select_all").click(function(){
				$('.shopping_select').attr("checked",this.checked)
			})
	  	})
	</script>
</body>
</html>

